add_rules("mode.debug", "mode.release")


target("qjs")
  set_kind("shared")
  add_files("quickjs.c", "libregexp.c", "libunicode.c", "cutils.c", "quickjs-libc.c", "libbf.c")
  add_headerfiles("*.h")
  add_includedirs(".")
  add_cflags("-g", "-O2", "-DEBUG", {force=true})
  on_load(function (target)
    local vf = "VERSION.h"
    if os.exists("./VERSION") then
      local vf = "VERSION"
    end
    -- lua string:trim http://lua-users.org/wiki/StringTrim
    local VERSION = io.readfile(vf):gsub("^%s*(.-)%s*$", "%1")
    print("VERSION=" .. VERSION .. "CONFIG_VERSION=\"".. VERSION .."\"")
    target:add("defines", "CONFIG_VERSION=\"".. VERSION .."\"", "_GNU_SOURCE", "CONFIG_BIGNUM")
  end)

-- target("qjsc")
--   set_kind("binary")
--   add_files("qjs.c", "qjsc.c", "quickjs.c", "libregexp.c", "libunicode.c", "cutils.c", "quickjs-libc.c", "libbf.c")
--   on_load(function (target)
--     local vf = "VERSION.h"
--     if os.exists("./VERSION") then
--       local vf = "VERSION"
--     end
--     -- lua string:trim http://lua-users.org/wiki/StringTrim
--     local VERSION = io.readfile(vf):gsub("^%s*(.-)%s*$", "%1")
--     print("VERSION=" .. VERSION .. "CONFIG_VERSION=\"".. VERSION .."\"")
--     target:add("defines", "CONFIG_VERSION=\"".. VERSION .."\"", "_GNU_SOURCE")
--   end)